package com.bah.tract.action;

import java.io.IOException;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import com.bah.tract.model.Project;

@Name("projectReportAction")
public class ProjectReportAction extends ReportAction {
	@In
	private ProjectReport projectReport;

	public void run() throws IOException {
		Map<String, Object> params = new HashMap<String, Object>();
		List<Project> projects = projectReport.getProjects();
		Long[] projectIds = new Long[projects.size()];
		for (int i = 0; i < projects.size(); i++) {
			projectIds[i] = projects.get(i).getId();
		}
		params.put("projects", projectIds);
		params.put("range_start", new java.sql.Date(projectReport.getStart()
				.getTime()));
		params.put("range_end", new Date(projectReport.getEnd().getTime()));
		runReport("/reports/project.prpt", params);
	}
}
